import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum, UnitType} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";
import UnitUtil from "../../utils/UnitUtil";
import {DataRouter} from "../../frame/dataSource/DataRouter";
import {EffectModel} from "../../frame/apiModel/adapterModel/model2/EffectModel";
import {ModelFactory} from "../../frame/apiModel/adapterModel/model5/ModelFactory";
import {TimeControllerOpt} from "../../controller/model/ControllerOpt";
import {TimeController} from "../../controller/TimeController";
import MathUtil from "../../frame/codeAdapter/MathUtil";
import {GlobalEnv} from "../../utils/GlobalEnv";
import {ChangeUnitType, RewardType} from "../../type/Type";
import {ConfigKey} from "../../constant/ConfigConstant";
import {TaskController} from "../../controller/TaskController";
import {ModelType} from "../../frame/apiModel/adapter/adapterInterface/model5/IModelFactory";

export default class HatchPetSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.hatchPetSkill) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        this.hatchPetSkill(activeUnit, targetUnit)
        return success;
    }

    hatchPetSkill(activeUnit: UnitModel, targetUnit: UnitModel) {
        const hatchRange = 300;

        const player = PlayerFactory.getInstance().getUnitOwner(activeUnit);
        const hero = GlobalEnv.getHero(player);
        const isVaild = hero;
        if (isVaild) {
        } else {
            Logger.toastProduct('请选择人物后再操作宠物!', player);
            return;
        }

        // const activeLoc = GetUnitLoc(activeUnit);
        const activeUnitId = activeUnit.strId;


        // let flog = false;

        // const x = GetLocationX(activeLoc);
        // const y = GetLocationY(activeLoc);
        //
        // ForceUtil.forUnitsInRange(x, y, hatchRange,
        //     (unit: unit) => {
        //         const filterUnit = unit;
        //         const filterPlayer = GetOwningPlayer(filterUnit);
        //         if (IsPlayerAlly(filterPlayer, player)) {
        //         } else {
        //             return;
        //         }
        //         const filterTypeId = GetUnitTypeId(filterUnit);
        //         const filterUnitId = Util.toShortStrId(filterTypeId);
        //         if (filterUnitId === activeUnitId) {
        //             return;
        //         }
        //         flog = true;
        // })

        const targetUnitId = targetUnit.strId;

        if (targetUnitId === activeUnitId) {
        } else {
            Logger.toastProduct('附近没有其他可以用来孵蛋的同类', player);
            return;
        }
        const unitId = activeUnit.strId;
        const petData = DataRouterUtil.getPetDataByGetId(unitId);

        if (petData) {
            const rewardId = petData.hatch_eggs;
            TaskController.getInstance().reward(activeUnit, targetUnit, RewardType.bag, rewardId);
        }
    }

}